package day6;

import org.junit.Test;

public class HomeWork {
    @Test
    public void test1() {
        String str = "";
        char[] chars = str.toCharArray();
        int start = 0;
        int end = chars.length - 1;

        while ((start <= end) && (chars[start] == '-')) {
            start++;
        }
        while ((start <= end) && (chars[end] == '-')) {
            end--;
        }
        String newStr = str.substring(start, end + 1);
        System.out.println(newStr);
    }

    @Test
    public void test2() {
        String str = "--Java Android--";
        String newStr = trim(str);
        System.out.println(newStr);
    }

    private String trim(String str) {
        char[] chars = str.toCharArray();
        int start = 0;
        int end = chars.length - 1;

        while ((start <= end) && (chars[start] == '-')) {
            start++;
        }
        while ((start <= end) && (chars[end] == '-')) {
            end--;
        }
        return str.substring(start, end + 1);
    }

    // 3、使用String类中的split()函数，统计出“this is my homework! I must finish it!”中单词的个数。
    @Test
    public void test3() {
        String str = "this is my homework! I must finish it!";
        String[] array = str.split(" ");
        System.out.println(array.length);
    }
}
